package com.ls.kdlss.util;

import android.content.Context;
import android.os.CountDownTimer;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2016/9/28.
 */

public class IsPhoneAndNull {

    public final static int PHONE = 0;
    public final static int CODE = 1;

    public static boolean isPhoneAndCod(Context context, String phone, int type) {
        String typs = "";

        if (type == 0) {
            typs = "手机号";
            if (phone.equals("")) {
                Toast.makeText(context, typs + "不能为空", Toast.LENGTH_SHORT).show();
                return false;
            } else {
                if (isphone(phone)) {
                    return isphone(phone);
                } else {
                    Toast.makeText(context, "这不是一个合格的手机号", Toast.LENGTH_SHORT).show();
                    return isphone(phone);
                }

            }
        } else {
            typs = "验证码";
            if (phone.equals("")) {
                Toast.makeText(context, typs + "不能为空", Toast.LENGTH_SHORT).show();
                return false;
            }
            return true;
        }
    }


    public static Boolean isphone(String phone) {

        Log.e("text", phone);
        return isMobileNO(phone);//boolean
    }

    public static boolean isMobileNO(String mobiles) {
//		Pattern p = Pattern
//				.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
        //"^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$"

        String regExp ="^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|17[0-9]{9}$|18[0-9]{9}$\n";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }


    public static void onTime(final Button view) {


        view.setEnabled(false);

        new CountDownTimer(60000, 1000) {
            public void onTick(long millisUntilFinished) {
                view.setText("" + millisUntilFinished / 1000 + "秒");

            }

            public void onFinish() {
                view.setText("获取");
                view.setEnabled(true);
            }
        }.start();

    }

}
